CROSS_COMPILE   = 

FEATURE         += DEBUG

CC              = $(CROSS_COMPILE)gcc
LD              = $(CROSS_COMPILE)gcc
STRIP           = $(CROSS_COMPILE)strip
SED             = sed

TARGET          = socks5d
SRCDIRS         = . socks
EXCLUDE_FILES   = 
INCLUDES        = 
LIBS            = 
STATICLIBS      = 

VERSION         = 

CFLAGS          += #-pg
LDFLAGS         += -lanl #-pg
DFLAGS          += -MM

ifeq ($(findstring DEBUG, $(FEATURE)),)
CFLAGS          += -DNDEBUG
endif

CFLAGS          := $(CFLAGS) $(addprefix -D, $(FEATURE)) \
                   $(INCLUDES) $(addprefix -I, $(SRCDIRS)) -DVERSION=\"$(VERSION)\" \
                   -pipe -Wall -Wextra
LDFLAGS         := $(LDFLAGS) $(LIBS)

SRCS            = $(filter-out $(EXCLUDE_FILES), $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.c)))
OBJS            = $(SRCS:.c=.o)
DEPENDS         = $(SRCS:.c=.d)

all: $(TARGET)
ifeq ($(findstring -DNDEBUG, $(CFLAGS)), -DNDEBUG)
	@echo STRIP $(TARGET)
	@$(STRIP) $(TARGET)
endif

$(TARGET): $(OBJS)
	@echo LD $@
	@$(LD) -o $@ $(filter %.o ,$+) $(LDFLAGS)

%.o : %.c
	@echo CC $@
	@$(CC) -c $(CFLAGS) $< -o $@

%.d: %.c
	@echo GEN DEPENDENT $@
	@$(CC) $(DFLAGS) $(CFLAGS) $< | $(SED) 's,$(basename $(notdir $<))\.o\s*:, $(basename $<).o: ,g' > $@

sinclude $(DEPENDS)

clean:
	$(RM) $(OBJS) $(DEPENDS)

distclean: clean
	$(RM) $(TARGET)
